<%--  This file is part of LitSearch.

    LitSearch is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    LitSearch is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with LitSearch; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA --%>

<%@ page import=" java.util.regex.*" %>
<%@ page import=" java.lang.String" %>
<%@ page import=" java.util.*" %>

<jsp:useBean scope="session" id="languageObj" class="de.fhbrs.litsearch.LanguageBean"  />
<jsp:useBean scope="session" id="settingsObj" class="de.fhbrs.litsearch.SettingsBean" />

<jsp:useBean scope="session" id="userObj" class="de.fhbrs.litsearch.UserBean" />
<jsp:useBean scope="session" id="mySearch" class="de.fhbrs.litsearch.SearchBean" />


<jsp:setProperty name="mySearch" property="*" />
<%
mySearch.setResultsPerPage(settingsObj.getResultsPerPageFromDB());
mySearch.setMaximumHits(settingsObj.getSearchLimitFromDB());
mySearch.setLanguage(languageObj);
mySearch.setSettingsObject(settingsObj);
mySearch.setUserObject(userObj);
String searchMessage="";	
boolean error=false;
mySearch.setErrorMessage("");
mySearch.setView("search");

mySearch.setStartwert(request.getParameter("startwert"));
mySearch.toggleWalletString(request.getParameter("toggle"));
mySearch.setOrderBy(request.getParameter("orderBy"));
mySearch.setOrderDirection(request.getParameter("orderDirection"));
if (request.getParameter("Reset") == null) {
	mySearch.setSearchWord(request.getParameter("searchString"));
	mySearch.setSearchWordTitle(request.getParameter("searchWordTitle"));
	mySearch.setSearchWordAuthor(request.getParameter("searchWordAuthor"));

	mySearch.setSearchWordSignatur(request.getParameter("searchWordSignatur"));
	mySearch.setSearchWordEditor(request.getParameter("searchWordEditor"));
	mySearch.setSearchWordISBN(request.getParameter("searchWordISBN"));
	mySearch.setSearchWordISSN(request.getParameter("searchWordISSN"));
	mySearch.setSearchWordTitle2(request.getParameter("searchWordTitle2"));
	mySearch.setSearchWordInstitute(request.getParameter("searchWordInstitute"));
	mySearch.setSearchWordPublisher(request.getParameter("searchWordPublisher"));
	mySearch.setSearchWordJournal(request.getParameter("searchWordJournal"));
	mySearch.setSearchWordYear(request.getParameter("searchWordYear"));
	mySearch.setSearchWordMinYear(request.getParameter("searchWordMinYear"));
	mySearch.setSearchWordMaxYear(request.getParameter("searchWordMaxYear"));
	mySearch.setSearchWordInventorynumber(request.getParameter("searchWordInventorynumber"));
	mySearch.setSearchWordShelf(request.getParameter("searchWordShelf"));
	mySearch.setStartwert(request.getParameter("startwert"));
	mySearch.setExtSearch(request.getParameter("extsearch"));
}
else {
	mySearch.resetSearch();
}

if (request.getParameter("Suchen") != null) {
	mySearch.setCheckboxArticle(request.getParameter("checkboxArticle"));
	mySearch.setCheckboxBook(request.getParameter("checkboxBook"));
	mySearch.setCheckboxGreylit(request.getParameter("checkboxGreylit"));
}

if (request.getParameter("startwert") != null && request.getParameter("startwert").compareTo("0") != 0) {
	String startwert_str = request.getParameter("startwert");
	int startwert = Integer.parseInt(startwert_str);
	mySearch.getMedia(startwert);
} else {
	mySearch.getMedia();
}

%>

<script language="javascript">

    function clearSimpleForm() {
	    document.simpleSearchForm.searchString.value = "";
	}
	
</script>

<%
if(!mySearch.isExtSearch()){
%>

<form method="post" name="simpleSearchForm" action="index.jsp?content=search">
	<div style="width:600px;">
		<table>
			<tr>
				<td><b><%=languageObj.getTextFor("search.searchWord")%>:</b></td>
				<td><input type="text" name="searchString" value="<%= mySearch.getSearchWordHtml() %>" /></td>
				<td>
					<input type="submit" name="Suchen" value="<%=languageObj.getTextFor("search.SendRequest")%> "/>
					<input type="submit" name="Reset" value="<%=languageObj.getTextFor("search.Reset")%>" />
				</td>
			</tr>
			<tr>
				<td><b><%=languageObj.getTextFor("search.mediatype")%></b></td>
				<td colspan="2">
					<input type="checkbox" name="checkboxArticle" value="checked" <%= mySearch.getCheckboxArticle() %>><%= languageObj.getTextFor("export.article") %></input>
					<input type="checkbox" name="checkboxBook" value="checked" <%= mySearch.getCheckboxBook() %>><%= languageObj.getTextFor("export.book") %></input>
					<input type="checkbox" name="checkboxGreylit" value="checked" <%= mySearch.getCheckboxGreylit() %>><%= languageObj.getTextFor("export.greylit") %></input>
					<input type="hidden" name="newSearch" value="yes" />
				</td>
			</tr>
		</table>
	</div>
</form>
<script type="text/javascript">
	<!--
	 document.searchForm.searchString.focus();
	 document.searchForm.searchString.select();
	//-->
</script>

<%
}else{
%>

<script type="text/javascript">
<!--
function toggleMe(name){

	if(document.getElementById(name).style.visibility=='hidden'){
		//alert("Ist versteckt:"+name);	
		document.getElementById(name).style.visibility='visible';
	}else{
			//alert("Ist nicht 	versteckt:"+name);	
		document.getElementById(name).style.visibility='hidden';
		}
}
//-->
</script>

<form method="post" name="extendedSearchForm" action="index.jsp?content=search">
	
    
    <table cellpadding="0" >
		<tr>
			<td valign="top">	
				<table>
<%



// Namen der Setter Methoden
String[] felderArray ={"Title","Title2","Author","Signatur","Editor","ISBN","ISSN","Institute","Publisher","Journal","Inventorynumber","Shelf","Year"};
// Bezeichnung der Felder
String[] valuesArray ={mySearch.getSearchWordTitle(),mySearch.getSearchWordTitle2(),mySearch.getSearchWordAuthor(),mySearch.getSearchWordSignatur(),mySearch.getSearchWordEditor(),mySearch.getSearchWordISBN(),mySearch.getSearchWordISSN(),mySearch.getSearchWordInstitute(),mySearch.getSearchWordPublisher(),mySearch.getSearchWordJournal(),mySearch.getSearchWordInventorynumber(),mySearch.getSearchWordShelf(),mySearch.getSearchWordYear()};
// Bezeichnung der Felder
String[] nameArray ={languageObj.getTextFor("search.Title"),languageObj.getTextFor("search.Title2"),languageObj.getTextFor("search.Author"),languageObj.getTextFor("search.Signature"),languageObj.getTextFor("search.Editor"),languageObj.getTextFor("search.Isbn"),languageObj.getTextFor("search.Issn"),languageObj.getTextFor("search.Institute"),languageObj.getTextFor("search.Publisher"),"<a href=\"journals.jsp\" target=\"_new\">"+languageObj.getTextFor("search.Journal")+"</a>",languageObj.getTextFor("search.Inventory"),languageObj.getTextFor("search.Shelf"),languageObj.getTextFor("search.Year")};
// Inhalt der Felder
String[] selectArray ={mySearch.getSearchWideTitleHtml(),mySearch.getSearchWideTitle2Html(),mySearch.getSearchWideAuthorHtml(),mySearch.getSearchWideSignaturHtml(),mySearch.getSearchWideEditorHtml(),mySearch.getSearchWideISBNHtml(),mySearch.getSearchWideISSNHtml(),mySearch.getSearchWideInstituteHtml(),mySearch.getSearchWidePublisherHtml(),mySearch.getSearchWideJournalHtml(),mySearch.getSearchWideInventorynumberHtml(),mySearch.getSearchWideShelfHtml(),mySearch.getSearchWideYearHtml()};

for(int i=0;i<felderArray.length;i++){
String x=felderArray[i];

out.print("<tr id=\""+felderArray[i]+"\">");
out.print("<td><b>"+nameArray[i]+":</b></td>");
out.print("<td><input type=\"text\" name=\"searchWord"+felderArray[i]+"\" value=\""+valuesArray[i]+"\" size=\"36\" /></td>");
//out.print("<td><select name=\"searchWide"+felderArray[i]+"\"><option value=\"yes\" "+selectArray[i]+">"+languageObj.getTextFor("search.imprecise")+"</option><option value=\"no\" "+selectArray[i]+">"+languageObj.getTextFor("search.precise")+"</option></select></td>");
out.print("</tr>");
out.print("<input type=\"hidden\" name=\"searchWide"+felderArray[i]+"\" value=\"yes\">");
if(i==felderArray.length/2) {
%>
	<tr>
		<td><b><%=languageObj.getTextFor("search.mediatype")%></b></td>
		<td colspan="2">
			<input type="checkbox" name="checkboxArticle" value="checked" <%= mySearch.getCheckboxArticle() %>><%= languageObj.getTextFor("export.article") %></input>
			<input type="checkbox" name="checkboxBook" value="checked" <%= mySearch.getCheckboxBook() %>><%= languageObj.getTextFor("export.book") %></input>
			<input type="checkbox" name="checkboxGreylit" value="checked" <%= mySearch.getCheckboxGreylit() %>><%= languageObj.getTextFor("export.greylit") %></input>
		</td>
	</tr>
<%
	out.print("</table></td><td valign=\"top\"><table>");
}
}
%>
	
			<tr>
				<td>
				<b><%=languageObj.getTextFor("search.SomeYear")%></b>
				</td>
				<td colspan="3">
				<input type="text" name="searchWordMinYear" size="4" value="<%=mySearch.getSearchWordMinYear()%>" /> 
				 <%=languageObj.getTextFor("search.To")%>  
				<input type="text" name="searchWordMaxYear" size="4" value="<%=mySearch.getSearchWordMaxYear()%>" />
				</td>
			</tr>
			</table>
			</td>
		</tr>
		<!-- <tr style="height:10px;"><td></td></tr>
		<tr class="searchNavi"><td></td></tr> -->
		<tr>
			<td colspan="4" style="text-align:right"><input type="hidden" name="newSearch" value="yes" />
				<input type="hidden" name="startwert" value="<%= mySearch.getStartwert() %>" />
				<input type="submit" name="Suchen" value="<%=languageObj.getTextFor("search.SendRequest")%>" />
				<input type="submit" name="Reset" value="<%=languageObj.getTextFor("search.Reset")%>" />
			</td>
		</tr>
			
	</table>
</form>

<%
}
%>



<!--<table width="100%" border="1" cellpadding="4">
	<tr> 
		<td colspan="2" style="text-align:left;"><%= mySearch.getSearchMessage() %><%= mySearch.getErrorMessage() %></td>			
		<td style="text-align:right"> <%= mySearch.getResultInfo() %> </td>
	</tr>	
</table>-->
<br />
<div class="left"><%= mySearch.getSearchMessage() %><%= mySearch.getErrorMessage() %></div>
<div class="right" ><%= mySearch.getResultInfo() %></div><br />

<table width="100%" cellspacing="0" cellpadding="0">
	<tr class="searchNavi"><td></td></tr>
	<tr>
		<td style="text-align:left; vertical-align:top" ><%= mySearch.getPrevNavi() %></td>	
		<td style="text-align:center; vertical-align:top"><%= mySearch.getPageNavi() %></td>			
		<td style="text-align:right; vertical-align:top"><%= mySearch.getNextNavi() %></td>	

	</tr>
	
</table>

<%
if(mySearch.getErrorMessage().equals("") && mySearch.getTableHeader() != ""){
%>


<table cellpadding="10" style="border: 1px groove black; width:100%">




<%= mySearch.getTableHeader() %>
<%= mySearch.getSearchResults() %>

</table>
<%}%>
<table>
	<tr>
		<td style="text-align:left; vertical-align:top" ><%= mySearch.getPrevNavi() %></td>	
		<td style="text-align:center; vertical-align:top"><%= mySearch.getPageNavi() %></td>			
		<td style="text-align:right; vertical-align:top"><%= mySearch.getNextNavi() %></td>	

	</tr>
	<tr style="height:15px;"><td></td></tr>
	<tr class="searchNavi"><td></td></tr>
</table>

<div id="Arbeitsmappe"><div class="left"><b><a href="index.jsp?content=wallet"><%= languageObj.getTextFor("search.Wallet") %>:</a></b> <%= mySearch.walletSize() %> <%= languageObj.getTextFor("search.Elements") %></div></div>
<div id="export"><div class="right"><a href="export.jsp?do=bibtex&amp;what=search">BibTex-Export</a> | <a href="export.jsp?do=csv&amp;what=search">CSV-Export</a> | <a href="export.jsp?do=print&amp;what=search" target="_new"><%= languageObj.getTextFor("search.PrintView") %></a></div></div>
<div style="width:100%">&nbsp;</div>

<%
try{
//out.print(mySearch.getSqlSearch());
}catch(Exception e){}
%>